package components.toolbar.item
{
	import components.map.MapController;
	import components.map.utils.SceneItemType;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class ToolBarItemController
	{
		private var _target:Sprite;
		
		public function ToolBarItemController( target:Sprite )
		{
			_target = target;
			init();
		}
		
		private function init():void
		{
			var len:int = _target.numChildren;
			for( var i:int=0; i<len; i++ )
			{
				var dis:DisplayObjectContainer = _target.getChildAt(i) as DisplayObjectContainer;
				if( dis != null )
				{
					dis.mouseChildren = false;
				}
			}
			_target.addEventListener( MouseEvent.CLICK, onClick, false, 0, true );
		}
		
		private function onClick( e:MouseEvent ):void
		{
			var name:String = e.target.name;
			if( name=="npc" )
			{
				MapController.instance.dragItemType = SceneItemType.NPC;
			}
		}
	}
}